package modelLag;
import java.util.ArrayList;
/**
 * Write a description of class ForestContainer here.
 * 
 * @author (Anders Mortensen) 
 * @version (1.0 03-11-14)
 */
public class PersonContainer {
    // instance variables 
    private static PersonContainer instance;
    private ArrayList<Person> personList;

    /**
     * Constructor for objects of class ForestContainer
     */
    private PersonContainer() {
        personList = new ArrayList<Person>(); 
    }

    /**
     * 
     */
    public static PersonContainer getInstance() {
        if(instance ==null) {
            instance = new PersonContainer();
        }
        return instance;
    }
    
    public void addPerson(Person per) {
        personList.add(per);
    }
    
    public Person findPerson(String phone) {
        int i=0;
        boolean found = false;
        Person per = null;
        while(i<personList.size() && !found) {
            Person numb = personList.get(i);
            String number = numb.getPhone();
            if (number.equals(phone)){
                found = true;
                per = personList.get(i);
                
            }
            else {
                i++;
            }
        }
        return per;
    } 
    
    public void deletePerson(String phone) {
        int i=0;
        boolean found = false;
        while(i<personList.size() && !found) {
            Person numb = personList.get(i);
            String number = numb.getPhone();
            if (number.equals(phone)) {
                found = true;
                
            }
            else {
                i++;
            }
        }
        if (found) {
            personList.remove(i);
        }

    }
}




























